using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Controls;

namespace Lexware.InhouseTools.TeamFoundation
{
    public partial class WorkItemForm : Form
    {
        public WorkItemForm(WorkItem workItem)
        {
            InitializeComponent();

            WorkItemFormControl wiControl = new WorkItemFormControl();
            wiControl.Item = workItem;
            wiControl.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
            Controls.Add(wiControl);
            wiControl.Location = _dummyLabel.Location;
            wiControl.Size = _dummyLabel.Size;

            _workItem = workItem;
        }

        private WorkItem _workItem;

        public WorkItem WorkItem
        {
            get { return _workItem; }
            set { _workItem = value; }
        }

        private void _saveButton_Click(object sender, EventArgs e)
        {
            if (!_workItem.IsValid())
            {
                MessageBox.Show(this, "Work Item is not valid. Please check all required fields.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DialogResult = DialogResult.OK;
                Dispose();
            }
        }

        private void _cancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Dispose();
        }
    }
}